package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.QuestParams;
import com.hmall.search.pojo.SearchItem;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
public class SearchController {
   @Autowired
   private SearchService searchService;

    @GetMapping("hi")
    public String hi() {
        return "hi";
    }

    @GetMapping("suggestion")
    public List<String> getSuggestion(@RequestParam("key") String completion) throws IOException {
       return searchService. getSuggestion(completion);
    }
    @PostMapping("filters")
    public Map<String,List<String>> getFilters(@RequestBody QuestParams params) throws IOException {
        return searchService.getFilters(params);
    }
    @PostMapping("list")
    public PageDTO<SearchItem>searchList(@RequestBody QuestParams params)  {
        return searchService.searchList(params);
    }
}
